package cn.edu.nju.contact.contacts;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class ContactItemContainer<T extends ContactItemInterface<T>> {
	ArrayList<T> items;
	 
    public ContactItemContainer(){
    	items = new ArrayList<T>();
    }
 
    public void addData(T c)
    {
    	items.add(c);       
    }
    
    public Map<String, ArrayList<T>> getSortedData()
    {
    	Collections.sort(items);
    	
        Map<String, ArrayList<T>> results = new HashMap<String, ArrayList<T>>();
        ArrayList<T> contacts = null;
        String currletter = null;
 
        for (T c : items)
        {
            if (!c.getLabel().equals(currletter))
            {
                contacts = new ArrayList<T>();
                currletter = c.getLabel();
                results.put(currletter,contacts);
            }
            contacts.add(c);
        }
        return results; 
    }
}
